package com.ruoyi.app.controller

import com.github.binarywang.wxpay.exception.WxPayException
import com.ruoyi.app.common.Data
import com.ruoyi.app.service.PayApiService
import com.ruoyi.back.domain.dto.CartoonOrderDto
import com.ruoyi.back.domain.dto.Pic2PicOrderDto
import com.ruoyi.back.domain.dto.Text2PicOrderDto
import com.ruoyi.back.domain.dto.UserMemberOrderDto
import com.ruoyi.back.enums.PayTypeEnum
import com.ruoyi.back.service.UserMemberOrderService
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import javax.servlet.http.HttpServletRequest

@RestController
@RequestMapping("api/pay")
@Api(tags = ["支付api"])
class PayApiController {

    @Autowired
    private lateinit var payApiService: PayApiService

    @ApiOperation(value = "微信预支付")
    @PostMapping("createOrder")
    @Throws(WxPayException::class)
    fun <T> createOrder(userMemberOrderDto: UserMemberOrderDto): Data<T> = payApiService.createWxOrder(userMemberOrderDto)

    @ApiOperation("创建文生图微信预支付")
    @PostMapping("createText2PicOrder")
    fun <T> createText2PicOrder(text2PicOrderDto: Text2PicOrderDto): Data<T> = payApiService.createText2PicOrder(text2PicOrderDto)

    @ApiOperation("创建图生图微信预支付")
    @PostMapping("createPic2PicOrder")
    fun <T> createPic2PicOrder(pic2PicOrderDto: Pic2PicOrderDto): Data<T> = payApiService.createPic2PicOrder(pic2PicOrderDto)

    @ApiOperation("创建卡通头像微信预支付")
    @PostMapping("createCartoonOrder")
    fun <T> createCartoonOrder(cartoonOrderDto: CartoonOrderDto): Data<T> = payApiService.createCartoonOrder(cartoonOrderDto)


    @ApiOperation("创建阿里支付")
    @PostMapping("createAliOrder")
    fun createAliOrder(userMemberOrderDto: UserMemberOrderDto): Data<String> = payApiService.createAliOrder(userMemberOrderDto)

    @ApiOperation("创建文生图阿里预支付")
    @PostMapping("createText2PicAliOrder")
    fun createText2PicAliOrder(text2PicOrderDto: Text2PicOrderDto): Data<String> = payApiService.createText2PicAliOrder(text2PicOrderDto)

    @ApiOperation("创建图生图阿里预支付")
    @PostMapping("createPic2PicAliOrder")
    fun createPic2PicAliOrder(pic2PicOrderDto: Pic2PicOrderDto): Data<String> = payApiService.createPic2PicAliOrder(pic2PicOrderDto)

    @ApiOperation("创建卡通阿里预支付")
    @PostMapping("createCartoonAliOrder")
    fun createCartoonAliOrder(cartoonOrderDto: CartoonOrderDto): Data<String> = payApiService.createCartoonAliOrder(cartoonOrderDto)


    @ApiOperation(value = "微信支付回调", hidden = true)
    @PostMapping("wxNotify")
    fun wxNotify(@RequestBody xmlData: String): String = payApiService.wxNotify(xmlData)

    @ApiOperation(value = "阿里支付回调", hidden = true)
    @PostMapping("aliNotify")
    fun aliNotify(request: HttpServletRequest): String = payApiService.aliNotify(request)
}